package com.xm2.demo.system;

import com.xm2.demo.model.Stores;
import com.xm2.demo.system.shop.service.ShopService;
import com.xm2.demo.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * @Create
 * @create 2018-12-12 14:15
 * @Description：
 */
@Controller
@RequestMapping(value = "/system/")
public class SystemController {

    @Autowired
    private ShopService shopService;

    @GetMapping(value = "main")
    public String main(){
        return "main";
    }

    @PostMapping(value = "getShopByIds/{id}")
    @ResponseBody
    public List<String> getShop(@PathVariable Integer id){
        List<Stores> storesList = shopService.getShop(id);
        List<String> lists = new ArrayList<>();
        for (Stores stores : storesList) {
            lists.add(stores.getStoresName());
        }

        return lists;
    }

    @PostMapping(value = "bind/{id}")
    @ResponseBody
    public JsonResult bind(@PathVariable Integer id,@RequestBody String shop){
        shopService.bind(id,shop) ;
        return new JsonResult();
    }
}
